from idc import *
from idaapi import *
from idautils import *

# file name
func1 = 0x1002235A
# function name
func2 = 0x100012E0

count1 = 0

disasmStr = 'call    TraceInfo1'

for ref in CodeRefsTo(func2, 1):
    #print "    called from %s( 0x%x)" % (GetFunctionName(ref), ref)
    preRef = PrevHead(ref, 7)
    funrefStart = GetFunctionAttr(preRef, FUNCATTR_START)
    funref = get_func(funrefStart)
    print funref.startEA
    #print funrefStart
    preRef = PrevHead(preRef, 7)
    #print "    preRef 0x%x" % preRef
    #print GetMnem(preRef)
    #str1 = Dword(preRef+1)
    #print GetDisasm(preRef)

    funcname1 = GetString(GetOperandValue(preRef,0), -1, ASCSTR_C)
    count1 += 1
    #print funcname1
    #preRef < funref.startEA and 
    while GetDisasm(preRef) != disasmStr:
        preRef = PrevHead(preRef, 7)
    else:
        #print GetDisasm(preRef)
        preRef = PrevHead(preRef, 7)
        filename1 = GetString(GetOperandValue(preRef, 0), -1, ASCSTR_C)
        filename = filename1.rpartition('\\')[2].rstrip('.cpp')
        #print filename
        funcname = filename + '__' + funcname1
        print funcname
        #MakeNameEx(funrefStart, funcname, 1)

    #print GetString(str1, -1, ASCSTR_C)


print 'counts is: %d' % count1